#include "../mqserver/mq_queue.hpp"
#include <gtest/gtest.h>

bitmq::MsgQueueManager::ptr mqmp;

class MsgQueueTest : public testing::Environment
{
    virtual void SetUp()
    {
        mqmp = std::make_shared<bitmq::MsgQueueManager>("./data/meta.db");
    }

    virtual void TearDown()
    {
        // mqmp->clear();
    }
};

// TEST(queue_test, insert_test)
// {
//     std::unordered_map<std::string, std::string> map = {{"k1", "v1"}};
//     mqmp->declareQueue("q1", true, false, false, map);
//     mqmp->declareQueue("q2", true, false, false, map);
//     mqmp->declareQueue("q3", true, false, false, map);
//     mqmp->declareQueue("q4", true, false, false, map);
//     ASSERT_EQ(mqmp->size(), 4);
// }

TEST(queue_test, select_test)
{
    ASSERT_EQ(mqmp->exists("q3"), true);
    ASSERT_EQ(mqmp->exists("q1"), true);
    ASSERT_EQ(mqmp->exists("q2"), true);
    ASSERT_EQ(mqmp->exists("q4"), true);
    bitmq::MsgQueue::ptr mqp = mqmp->selectQueue("q2");
    ASSERT_EQ(mqp->name, "q2");
    ASSERT_EQ(mqp->durable, true);
    ASSERT_EQ(mqp->auto_delete, false);
    ASSERT_EQ(mqp->exclusive, false);
    ASSERT_EQ(mqp->getArgs(), std::string("k1=v1&"));
}

// TEST(queue_test, remove_test)
// {
//     mqmp->deleteQueue("q1");
//     ASSERT_EQ(mqmp->exists("q1"), false);
// }

int main(int argc, char *argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new MsgQueueTest);
    int t = RUN_ALL_TESTS();
    return 0;
}
